package org.iks.common.aop.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.iks.common.enums.IEnum;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;
import java.io.Serializable;

/**
 * Author kzou
 * Date 2024/5/26
 * Description: 枚举序列化 {@link org.iks.common.enums.IEnum}
 */
@JsonComponent
public class EnumJackSonSerializer extends JsonSerializer<IEnum<?>> {

    @Override
    public void serialize(IEnum<?> iEnum, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
            throws IOException {
        Serializable uniqueCode = iEnum.getUniqueCode();
        jsonGenerator.writeObject(uniqueCode);
    }

}
